﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;
using Model;

namespace DAL
{
  public   class MarkDAL
    {
      /// <summary>
      /// 链接字符串
      /// </summary>
      SqlConnection con = new SqlConnection(" Data Source=PC201609040948;Initial Catalog=TianTianDai_Db;Persist Security Info=True;User ID=sa;Pwd=123456");
      /// <summary>
      /// 发标预告显示功能
      /// </summary>
      /// <returns></returns>
      public List<Mark> Mark_Show()
      {
          con.Open();
          string sql = "select * from Mark";
          SqlDataAdapter adp = new SqlDataAdapter(sql,con);
          DataTable table = new DataTable();
          adp.Fill(table);
          con.Close();
          List<Mark> list = new List<Mark>();
          foreach (DataRow item in table.Rows)
          {
              Mark mark = new Mark();
              mark.MarkContent = item["MarkContent"].ToString();
              mark.MarkId = Convert.ToInt32(item["MarkId"]);
              mark.MarkPerson = item["MarkPerson"].ToString();
              mark.MarkTime = Convert.ToDateTime(item["MarkTime"]);
              mark.MarkTitle = item["MarkTitle"].ToString();
              list.Add(mark);
          }
          return list;
         
      }
      /// <summary>
      /// 发标预告的添加
      /// </summary>
      /// <param name="m"></param>
      /// <returns></returns>
      public int Mark_Insert (Mark m)
      {
          con.Open();
          string sql = "inset into Mark values ('"+m.MarkTitle+"','"+m.MarkTime+"','"+m.MarkContent+"','"+m.MarkPerson+"')";
          SqlCommand com = new SqlCommand(sql,con);
          return com.ExecuteNonQuery();
      }
      /// <summary>
      /// 发标预告的删除
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public int Mark_Delete(int id)
      {
          con.Open();
          string sql = "Delete from Mark where MarkId='" + id + "'";
          SqlCommand com = new SqlCommand(sql, con);
          return com.ExecuteNonQuery();
      }
     

      /// <summary>
      /// 发标预告的显示或修改第一步
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public Mark   Mark_details(int id)
      {
          con.Open();
          string sql = "select * from Mark Where UserInfoId='" + id + "'";
          SqlDataAdapter adp = new SqlDataAdapter(sql, con);
          DataTable table = new DataTable();
          adp.Fill(table);
          con.Close();
          List<Mark> list = new List<Mark>();
          foreach (DataRow item in table.Rows)
          {
              Mark mark = new Mark();
              mark.MarkContent = item["MarkContent"].ToString();
              mark.MarkId = Convert.ToInt32(item["MarkId"]);
              mark.MarkPerson = item["MarkPerson"].ToString();
              mark.MarkTime = Convert.ToDateTime(item["MarkTime"]);
              mark.MarkTitle = item["MarkTitle"].ToString();
              list.Add(mark);
          }
          return list.FirstOrDefault();
      }
      /// <summary>
      /// 发标预告的修改
      /// </summary>
      /// <param name="id"></param>
      /// <returns></returns>
      public int Mark_Edit(Mark m)
      {
          con.Open();
          string sql = "Update Mark set  MarkContent='" + m.MarkContent + "',MarkPerson='" + m.MarkPerson + "',MarkTime='" + m.MarkTime + "',MarkTitle='" + m.MarkTitle + "'";
          SqlCommand com = new SqlCommand(sql, con);
          return com.ExecuteNonQuery();
      }
      /// <summary>
      /// 发标预告的搜索
      /// </summary>
      /// <param name="RoleId"></param>
      /// <returns></returns>
      public List<Mark> Mark_Search(string MarkTitle)
      {
          con.Open();
          string sql = "select MarkId,MarkTitle,MarkContent,MarkPerson,MarkTime where MarkTitle like'" + MarkTitle + "'";
          SqlDataAdapter adp = new SqlDataAdapter(sql, con);
          DataTable table = new DataTable();
          adp.Fill(table);
          con.Close();
          List<Mark> list = new List<Mark>();
          foreach (DataRow item in table.Rows)
          {
              Mark mark = new Mark();
              mark.MarkContent = item["MarkContent"].ToString();
              mark.MarkId = Convert.ToInt32(item["MarkId"]);
              mark.MarkPerson = item["MarkPerson"].ToString();
              mark.MarkTime = Convert.ToDateTime(item["MarkTime"]);
              mark.MarkTitle = item["MarkTitle"].ToString();
              list.Add(mark);
          }
          return list;
      }





    
    }
}
